#include <QCoreApplication>
#include <QLocale>
#include <QTranslator>
#include "qbaiduaiio.h"

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "wenxinyiyan-qt-demo_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            break;
        }
    }

    QBaiduAIIO cAI;
    QTextStream qin(stdin);
    QTextStream qout(stdout);
    qin.setEncoding (QStringConverter::System);     //输入编码设为System
    qout.setEncoding (QStringConverter::System);    //输出编码设为System

    while (1)
    {
        QString sAsk,sResult;
        qout << "请输入问题:" << Qt::endl;
        qin >> sAsk;
        if (0 == sAsk.compare("q"))
            break;
        cAI.Ask(sAsk, sResult);
        qout << "回复: \n" << "  " << sResult << Qt::endl;
    }

    return a.exec();
}
